# 管理端-基礎接口
from flask import Blueprint, request
from admin_route.basic import addNewDict, addNewDictItem, addNewMenu, deleteDictById, deleteDictItemById, deleteMenuById, getAllDictionarys, getDictItemList, getDictItemPage, getDictList, getDictPage, getMenuList, isPsdTrue, updateDictById, updateDictItemById, updateMenuById, uploadFile

routes_basic = Blueprint('routes', __name__)

@routes_basic.route("/uploadFile", methods=['POST'])
def getFile():
    file = request.files['file']
    dest = uploadFile(file)
    print(dest)
    return dest

@routes_basic.route("/login", methods=['POST'])
def login():
    data = request.get_json()
    account = data.get('account', None)
    password = data.get('password', None)
    dest = isPsdTrue(account,password)
    print(dest)
    return dest

# 字典操作
@routes_basic.route("/dictionary/list", methods=['GET'])
def getDictionaryList():
    res = getDictList()
    return res

# 初始化获取字典
@routes_basic.route("/dictionary", methods=['GET'])
def getAllDictionaryList():
    res = getAllDictionarys()
    return res



# 字典分页
@routes_basic.route("/dictionary/page", methods=['GET'])
def getDictionaryPages():
    page = request.args.get('page')
    pageSize = request.args.get('pageSize')
    res = getDictPage(page, pageSize)
    return res


@routes_basic.route("/dictionary", methods=['PUT'])
def updateDictionary():
    data = request.get_json()
    id = data.get('id')
    res = updateDictById(id, data)
    return res


@routes_basic.route("/dictionary", methods=['POST'])
def addDictionary():
    data = request.get_json()
    res = addNewDict(data)
    return res


@routes_basic.route("/dictionary", methods=['DELETE'])
def deleteDictionary():
    id = request.args.get('id')
    res = deleteDictById(id)
    return res
# 字典項操作
# 字典分页


@routes_basic.route("/dictionaryItem/page", methods=['GET'])
def getDictionaryItemPages():
    page = request.args.get('page')
    pageSize = request.args.get('pageSize')
    id = request.args.get('categoryId')
    res = getDictItemPage(page, pageSize, id)
    return res


@routes_basic.route("/dictionaryItem/list", methods=['GET'])
def getDictionaryItemList():
    id = request.args.get('categoryId')
    print('getDictionaryItemList', id)
    res = getDictItemList(id)
    return res


@routes_basic.route("/dictionaryItem", methods=['PUT'])
def updateDictionaryItem():
    data = request.get_json()
    id = data.get('id')
    res = updateDictItemById(id, data)
    return res


@routes_basic.route("/dictionaryItem", methods=['POST'])
def addDictionaryItem():
    data = request.get_json()
    print('addDictionaryItem', data)
    res = addNewDictItem(data)
    return res


@routes_basic.route("/dictionaryItem", methods=['DELETE'])
def deleteDictionaryItem():
    id = request.args.get('id')
    res = deleteDictItemById(id)
    return res

@routes_basic.route("/menu/list", methods=['GET'])
def getAllMenu():
    res = getMenuList()
    return res


@routes_basic.route("/menu", methods=['POST'])
def saveMenu():
    data = request.get_json()
    print('saveMenu', data)
    res = addNewMenu(data)
    return res


@routes_basic.route("/menu", methods=['PUT'])
def updateMenu():
    data = request.get_json()
    id = data.get('id')
    res = updateMenuById(id, data)
    return res


@routes_basic.route("/menu", methods=['DELETE'])
def deleteMenu():
    id = request.args.get('id')
    res = deleteMenuById(id)
    return res
